package com.qf.java2007.service.impl;

import com.qf.java2007.mapper.AdminMapper;
import com.qf.java2007.mapper.ReaderCardMapper;
import com.qf.java2007.mapper.ReaderInfoMapper;
import com.qf.java2007.pojo.ClassInfo;
import com.qf.java2007.pojo.ReaderCard;
import com.qf.java2007.pojo.ReaderInfo;
import com.qf.java2007.service.ReaderCardService;
import com.qf.java2007.web.controller.AdminController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author AzureSky_X
 * @Date 2021/3/9 16:46
 * @Version 1.0
 */
@Service
@Transactional
public class ReaderCardServiceImpl implements ReaderCardService {

    @Autowired
    private ReaderInfoMapper readerInfoMapper;
    @Autowired
    private ReaderCardMapper readerCardMapper;
    @Override
    public ReaderCard login(String readerName, String password) {
        ReaderCard readerCard = readerCardMapper.findByName(readerName);

        if(readerCard != null) {
            if (readerCard.getPassword().equals(password)) {
                return readerCard;
            } else {
                throw new RuntimeException("账号或密码错误！");
            }
        } else {
            throw new RuntimeException("账户不存在，请联系管理员！");
        }
    }
    /**
     * 根据id查询借阅人详细信息
     * @param readerId
     * @return
     */
    @Override
    public ReaderInfo findReaderCardById(Long readerId) {
        return readerInfoMapper.findReaderCardById(readerId);
    }
    /**
     * 更新借阅人信息
     * @param readerInfo
     */
    @Override
    public void update(ReaderInfo readerInfo) {
        readerInfoMapper.update(readerInfo);
        Long readerId = readerInfo.getReaderId();
        String username = readerInfo.getUsername();
        readerInfoMapper.updateName(username,readerId);
    }
    /**
     * 更新密码
     * @param
     */

    @Override
    public void updatePwd(String reNewPasswd,String readerId) {
        readerCardMapper.updatePwd(reNewPasswd, readerId);

    }

    @Override
    public List<ReaderInfo> findAll() {
        return readerInfoMapper.findAll();
    }




}
